package com.lanou3g.ptp.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@ApiModel
public class Diary implements Serializable {

    @ApiModelProperty(name = "日志id", hidden = true)
    private Long id;

    @ApiModelProperty("学生id")
    private Long studentId;

    @ApiModelProperty("任务id")
    private Long taskId;

    @JsonIgnore
    @ApiModelProperty(name = "图片", hidden = true)
    private String img;

    @ApiModelProperty("日志内容")
    private String content;

    @ApiModelProperty(name = "是否推优", hidden = true)
    private Boolean excellent;

    @ApiModelProperty(name = "状态", hidden = true)
    private Integer status;

   @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(name = "创建时间", hidden = true)
    private Date createTime;

    @JsonIgnore
    @ApiModelProperty(name = "更新时间", hidden = true)
    private Date updateTime;

    @ApiModelProperty("任务名")
    private String taskName;
    @ApiModelProperty("图片数组")
    private String[] imgs;
    @ApiModelProperty(hidden = true)
    private String studentName;
    @ApiModelProperty(hidden = true)
    private String head;
    @ApiModelProperty(hidden = true)
    private List<Like> likes;
    @ApiModelProperty(hidden = true)
    private List<Comment> comments;
    @ApiModelProperty(hidden = true)
    private Boolean isLiked;
    @ApiModelProperty(hidden = true)
    private Boolean isMine;

    public void setImg(String img) {
        this.img = img;
        if (img != null) {
            imgs = img.split(",");
        }
    }

    public void setImgs(String[] imgs) {
        this.imgs = imgs;
        if (imgs != null && imgs.length > 0) {
            StringBuilder builder = new StringBuilder();
            for (String img : imgs) {
                builder.append(img).append(",");
            }
            builder.deleteCharAt(builder.length() - 1);
            this.img = builder.toString();
        }
    }

}
